0 /// Write a program that reads a text file and inserts line numbers in front of each of its lines.
1 /// The result should be written to another text file.
2 
3 using System;
4 using System.IO;
5 
6 
7 namespace c_sh_II_lek_6_files
8 {
9     class zad1
10     {
11         static void Main()
12         {
13             string soureceFile = @"..\..\zad3.cs";
14             string lineNum = @"..\..\zad3_lineNum.cs";
15             string line;
16             int n = 0;
17 
18             if (File.Exists(lineNum))
19             {
20                 File.Delete(lineNum);
21             }
22 
23             using (StreamWriter sw = new StreamWriter(lineNum))
24             {
25                 using (StreamReader sr = new StreamReader(soureceFile))
26                 {
27                     line = sr.ReadLine();
28                     while (line != null)
29                     {
30                         sw.WriteLine(n + " " + line);
31                         line = sr.ReadLine();
32                         n++;
33                     }
34                 }
35             }
36         }
37     }
38 }
